using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShivamEMR.Model.Domain.PatientDomain;
using ShivamEMR.Model.DataInterfaces.PatientDataInterf;
using ShivamEMR.Model.DataInterfaces.MedicalDataInterf;
using ShivamEMR.Model;

namespace ShivamEMR.Web.Areas.Patient.Controllers
{   
    public class PatientTreatmentController : Controller
    {
		private readonly IPatientRepository patientRepository;
		private readonly ITreatmentTypeRepository treatmenttypeRepository;
		private readonly ITreatmentStatusRepository treatmentstatusRepository;
		private readonly IPatientTreatmentRepository patienttreatmentRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public PatientTreatmentController() //: this(new PatientRepository(), new TreatmentTypeRepository(), new TreatmentStatusRepository(), new PatientTreatmentRepository())
        {
            this.patientRepository = Registry.RepositoryFactory.GetPatientRepository();
            this.treatmenttypeRepository = Registry.RepositoryFactory.GetTreatmentTypeRepository();
            this.treatmentstatusRepository = Registry.RepositoryFactory.GetTreatmentStatusRepository();
            this.patienttreatmentRepository = Registry.RepositoryFactory.GetPatientTreatmentRepository();
        }

        public PatientTreatmentController(IPatientRepository patientRepository, ITreatmentTypeRepository treatmenttypeRepository, ITreatmentStatusRepository treatmentstatusRepository, IPatientTreatmentRepository patienttreatmentRepository)
        {
			this.patientRepository = patientRepository;
			this.treatmenttypeRepository = treatmenttypeRepository;
			this.treatmentstatusRepository = treatmentstatusRepository;
			this.patienttreatmentRepository = patienttreatmentRepository;
        }

        //
        // GET: /PatientTreatment/

        public ViewResult Index()
        {
            return View(patienttreatmentRepository.All);//Including(patienttreatment => patienttreatment.Patient, patienttreatment => patienttreatment.TreatmentType, patienttreatment => patienttreatment.Medications, patienttreatment => patienttreatment.Diagnosis, patienttreatment => patienttreatment.Consultations));
        }

        //
        // GET: /PatientTreatment/Details/5

        public ViewResult Details(System.Guid id)
        {
            return View(patienttreatmentRepository.Find(id));
        }

        //
        // GET: /PatientTreatment/Create

        public ActionResult Create()
        {
			ViewBag.PossiblePatients = patientRepository.All;
			ViewBag.PossibleTreatmentTypes = treatmenttypeRepository.All;
			ViewBag.PossibleTreatmentStatus = treatmentstatusRepository.All;
            return View();
        } 

        //
        // POST: /PatientTreatment/Create

        [HttpPost]
        public ActionResult Create(PatientTreatment patienttreatment)
        {
            if (ModelState.IsValid) {
                patienttreatmentRepository.Create(patienttreatment);
                patienttreatmentRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossiblePatients = patientRepository.All;
				ViewBag.PossibleTreatmentTypes = treatmenttypeRepository.All;
				ViewBag.PossibleTreatmentStatus = treatmentstatusRepository.All;
				return View();
			}
        }
        
        //
        // GET: /PatientTreatment/Edit/5
 
        public ActionResult Edit(System.Guid id)
        {
			ViewBag.PossiblePatients = patientRepository.All;
			ViewBag.PossibleTreatmentTypes = treatmenttypeRepository.All;
			ViewBag.PossibleTreatmentStatus = treatmentstatusRepository.All;
             return View(patienttreatmentRepository.Find(id));
        }

        //
        // POST: /PatientTreatment/Edit/5

        [HttpPost]
        public ActionResult Edit(PatientTreatment patienttreatment)
        {
            if (ModelState.IsValid) {
                patienttreatmentRepository.Update(patienttreatment);
                patienttreatmentRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossiblePatients = patientRepository.All;
				ViewBag.PossibleTreatmentTypes = treatmenttypeRepository.All;
				ViewBag.PossibleTreatmentStatus = treatmentstatusRepository.All;
				return View();
			}
        }

        //
        // GET: /PatientTreatment/Delete/5
 
        public ActionResult Delete(System.Guid id)
        {
            return View(patienttreatmentRepository.Find(id));
        }

        //
        // POST: /PatientTreatment/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(System.Guid id)
        {
            var pt = patienttreatmentRepository.Find(id);
            patienttreatmentRepository.Delete(pt);
            patienttreatmentRepository.Save();

            return RedirectToAction("Index");
        }
    }
}

